<template>
  <div>
    <el-form
      ref="ruleForm"
      :model="ruleForm"
      :rules="rules"
      class="demo-ruleForm"
      label-width="100px"
    >
      <el-form-item label="旧登录密码" prop="oldPassword">
        <el-input
          v-model="ruleForm.oldPassword"
          show-password
          size="small"
        ></el-input>
      </el-form-item>
      <el-form-item label="新登录密码" prop="newPassword">
        <el-input
          v-model="ruleForm.newPassword"
          show-password
          size="small"
        ></el-input>
      </el-form-item>
      <div class="w-100 ws flex">
        <el-button size="small" type="primary" @click="determine(1)"
          >确定
        </el-button>
        <el-button size="small" @click="determine(2)">取消</el-button>
      </div>
    </el-form>
  </div>
</template>
<script>
import { passWord } from "@/assets/js/homePage";

export default {
  data() {
    return {
      ruleForm: {
        oldPassword: "",
        newPassword: "",
      },
      rules: {
        oldPassword: [
          { required: true, message: "请输入旧登录密码", trigger: "blur" },
        ],
        newPassword: [
          { required: true, message: "请输入新登录密码", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    async determine(e) {
      let num = null;
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          num = valid;
        }
      });
      if (num) {
        if (e === 1) {
          let res = await passWord(this.ruleForm);
          if (res.code === 200) {
            this.$emit("passWord", false);
            this.$refs.ruleForm.resetFields();
          }
        }
      }
      if (e === 2) {
        this.$refs.ruleForm.resetFields();
        this.$emit("passWord", false);
      }
    },
  },
};
</script>
<style scoped></style>
